<?php

class SiteController extends Controller
{

    public function filters()
    {
        return array(
            'accessControl',
            'postOnly + delete',
        );
    }

    public function accessRules()
    {
        return array(
            array('allow',
                'actions' => array('error'),
                'users' => array('*'),
            ),
            array('allow',
                'actions' => array('index'),
                'users' => array('@'),
            ),
            array('deny',
                'users' => array('*'),
            ),
        );
    }

    public function actions()
    {
        return array(
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    public function actionIndex()
    {
        $contracts = Contract::model()->findAllByAttributes(array(), array('order' => 'contract_id DESC', 'limit' => 5));
        $this->render('index', array(
            "contracts" => $contracts,
        ));
    }

    public function actionError()
    {
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest) {
                echo $error['message'];
            } else {
                $this->render('error', $error);
            }
        }
    }
}